package com.hzdl.hotel.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzdl.hotel.bean.Check;
import com.hzdl.hotel.bean.Customer;
import com.hzdl.hotel.bean.GuestRoom;
import com.hzdl.hotel.bean.RoomBook;
import com.hzdl.hotel.mapper.RoomMapper;
import com.hzdl.hotel.service.RoomService;
import com.hzdl.hotel.vo.CheckVo;
import com.hzdl.hotel.vo.GuestRoomVo;
import com.hzdl.hotel.vo.RoomBookVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomMapper rm;
    @Override
    public PageInfo findRoomByWhere(GuestRoomVo grv) {
        PageHelper.startPage(grv.getPage(),grv.getLimit());
        List<GuestRoom> gList = rm.findRoomByWhere(grv);
        PageInfo pageInfo = new PageInfo(gList);
        return pageInfo;
    }

    @Override
    public int insertRoom(GuestRoomVo grv) {
        return rm.insertRoom(grv);
    }

    @Override
    public int updateRoom(GuestRoomVo grv) {
        return rm.updateRoom(grv);
    }

    @Override
    public int deleteRoom(Integer hId) {
        return rm.deleteRoom(hId);
    }

    @Override
    public List<Check> findCustomer(String loginName) {
        return rm.findCustomer(loginName);
    }

    @Override
    public Check findByHId(Integer hId) {
        return null;
    }

    @Override
    public int changeRoom(CheckVo checkVo) {
        int row=rm.returnRoom(checkVo.gethId());
        row+=rm.orderRoom(checkVo.getHId1());
        row+=rm.updateRoomCheckInfo(checkVo);
        row+=rm.insertRoomCheckInfo(checkVo);
        return row;
    }

    @Override
    public GuestRoom findRoomByHId(Integer hId) {
        return rm.findRoomByHId(hId);
    }

    @Override
    public Customer findCustomerByLoginName(String loginName) {
        return rm.findCustomerByLoginName(loginName);
    }

    @Override
    public int returnRoom(CheckVo checkVo) {
        int row=rm.returnRoom(checkVo.gethId());
        row+=rm.updateRoomCheckInfo(checkVo);
        return row;
    }

    @Override
    public List<RoomBook> findAllRoom(RoomBookVo roomBookVo) {
        return rm.findAllRoom(roomBookVo);
    }

    @Override
    public Check findCustomer1(CheckVo checkVo) {
        return rm.findCustomer1(checkVo);
    }

    @Override
    public Check findCustomer2(CheckVo checkVo) {
        return rm.findCustomer2(checkVo);
    }
}
